	<?php
	// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

		        $actualPath = dirname(__FILE__) . '/';
		        $actualPath = str_replace('\\', '/', $actualPath);
				$upDir = substr( $actualPath, 0, strrpos( $actualPath, '/') );
				$upDir = substr( $actualPath, 0, strrpos( $upDir, '/') );
				$upDir = substr( $actualPath, 0, strrpos( $upDir, '/') );
				$actualPath = substr( $upDir, 0, strrpos( $upDir, '/') );

                $dir = ".";
                $directories = array();
                $files = array();

                function recursedir($rootdir){
                        $directories = array();
                        $files = array();
                        $dir = (substr($rootdir, -1) == '/') ? substr($rootdir, 0, -1) : $rootdir;

                        if(is_dir($dir)){
                                if($handle = @opendir($dir)){
                                        while(false !== ($file = readdir($handle))){

                                                if($file != "." && $file != ".." && $file !=(substr($file, strlen($file) - 6) == '.cache') && $file !=(substr($file, strlen($file) - 4) == '.spc') && $file !=(substr($file, strlen($file) - 4) == '.png') && $file !=(substr($file, strlen($file) - 4) == '.gif') && $file !=(substr($file, strlen($file) - 4) == '.jpg')){
                                                        $filename = $dir.'/'.$file;
                                                        if(is_dir($filename)){
                                                                $folder = $filename;

                                                                $files = array_merge($files, recursedir($filename));

                                                        } else {
// IGNORE FILES OVER xxMB in size
$filesize = filesize($filename);
//if($filesize <= 1048){ // 1k filesize
//if($filesize <= 1048576){ // 1MB FileSize
//if($filesize <= 2097200){ // 2MB FileSize
if($filesize <= 5242900){ // 5MB FileSize
                                                                $files[$filename] = filemtime($filename);
}
                                                        }
                                                }
                                        }
                                        closedir($handle);

                                } else {
                                        die('Could not open directory.' .$folder);
                                }
                        } else {
                                die('Invalid directory.');
                        }
                        return $files;
                }


                $files = recursedir("../");
                                ksort($files);
                                $highlight = 'alpha_asc';

				echo "<br /><br />";
				echo "<table border='0' cellspacing='1' cellpadding='1' width='95%' style='font-size: 11px;' align='center'>";
				echo "<tr><td>&nbsp;</td><td><img src='../includes/js/ThemeOffice/warning.png' width='15' height='15' alt='Suspect Files'> = Suspect Files (.cgi, .pl, .zip, .tar, .gz)</td><td colspan='2' align='center' class='right-col'><b>OwnerShip</b></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
				echo "<tr><td>&nbsp;</td><td class='right-col'><b>FileName</b></th><td width='50' align='center' class='right-col'><b>User</b></td><td width='50' align='center' class='right-col'><b>Group</b></td><td width='50' align='center' class='right-col'><b>Mode</b></td><td width='15'>&nbsp;</td><td width='50' align='center' class='right-col'><b>FileSize</b></td><td align='center' class='right-col'><b>Last Modified</b></td></tr>";

                foreach($files as $file => $timestamp){

						echo "<tr class='data-container'><td align='center' width='16' bgcolor='#ffffff'>";
						if  ($file ==(substr($file, strlen($file) - 3) == '.pl') || $file ==(substr($file, strlen($file) - 4) == '.cgi') || $file ==(substr($file, strlen($file) - 4) == '.zip') || $file ==(substr($file, strlen($file) - 4) == '.tar') || $file ==(substr($file, strlen($file) - 3) == '.gz') || $file ==(substr($file, strlen($file) - 4) == 'jpeg')) {
							echo "<img src='../includes/js/ThemeOffice/warning.png' width='15' height='15' alt='Suspect Files'>";
						} else { 
						echo "&nbsp;"; 
						}
						echo "</td>";

					if (substr(sprintf('%o', @fileperms($file)), -1) == '7') {
                        echo "<td bgcolor='yellow' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'><font color='red'>". $file ."</font></td>";
					} else {
                        echo "<td style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>". $file ."</td>";
					}
//                        echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>". fileowner("$file") ."</td>"; 
//                        echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>". filegroup("$file") ."</td>";

                        echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>";
                          
//                        $fileowner("$file");
//                        $userinfo = posix_getpwuid($fileowner);
//                        echo "". $userinfo ."";

	$isWin = (substr(PHP_OS, 0, 3) == 'WIN');
	if ($isWin)	{
	  echo fileowner("$file");
	} else {
	  $fileowneruid=fileowner($file);
	  $fileownerarray=posix_getpwuid($fileowneruid);
	  $fileowner=$fileownerarray['name']; 

	  if (function_exists( 'exec' )) {
		$ApacheAcc = exec("whoami");
	  }
		//		$UserAcc = get_current_user ();
	  if ( $fileowner == $ApacheAcc ) {
  	    echo "<font color=\"#FF9900\">". $fileowner ."</font>";  
	  } else {
	  echo $fileowner;
	  }
  }
echo "</td>"; 
echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>";
$isWin = (substr(PHP_OS, 0, 3) == 'WIN');
	if ($isWin)	{
	  echo filegroup("$file");
	} else {
	  $fileownergid=filegroup($file);
	  $groupownerarray=posix_getgrgid($fileownergid);
	  $groupowner=$groupownerarray['name']; 
      echo $groupowner;
	}
echo "</td>"; 




                        if (substr(sprintf('%o', @fileperms($file)), -1) == '7') 
                                { echo "<td align='center' bgcolor='yellow' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'><font color='red'>"; } 
                                elseif (substr(sprintf('%o', @fileperms($file)), -1) >= '5') 
                                        { echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'><font color='blue'>"; }
                                        else { echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'><font color='green'>"; }
                                        echo "". substr(sprintf('%o', @fileperms($file)), -4) ."";
                                        echo '</font>';
						echo "</td><td style='border-left: 1px solid #C0C0C0;' bgcolor='#ffffff' align='center'>&nbsp;</td><td style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>";

                        $filesize = filesize($file);
                        if($filesize >= 1048576){
                                echo round($filesize / 1048576, 1).'MB';
                        } else {
                                echo round($filesize / 1024, 1).'kb';
                        }
                        echo '</td><td style="border-bottom: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;">'.date('d M Y H:i:s', $timestamp)."</td>";

                        echo "</tr>\n";
                }
                echo "</table><br /><br />";

                ?>

		
		

<?php
		$tabs->endTab();
		$tabs->endPane();
?>		